package cb.wzby;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ListDemo5 {
    public static void main(String[] args) {
        List<Integer> l = new ArrayList<>(List.of(1, 2, 3, 5, 55, 666, 5, 1, 3));
        System.out.println(l);
        System.out.println(l.get(l.indexOf(55)));
        //.indexOf（）找到下标然后 .get（）根据下标找到所对应的数据
        System.out.println(l.get(5));
        System.out.println("=".repeat(20));
        //遍历读取
        for (Integer i : l) {
            System.out.printf("%d ", i);
        }
        System.out.println();
        //倒序读取
        for (int i = l.size() - 1; i >= 0; i--) {
            System.out.printf("%d ", l.get(i));
        }
        System.out.println();
        System.out.println("=".repeat(10));
        Collections.reverse(l);
        //Collections是工具类，reverse（）方法将集合颠倒
        System.out.println(l);
        System.out.println("===.shuffle（）洗牌乱序===");
        //.shuffle（）洗牌乱序
        Collections.shuffle(l);
        System.out.println(l);

    }
}
